package xin.mashibo.pattern.flyweight;

import java.util.HashMap;

/**
 * @author MaShibo
 * 日期 :  2019/1/28
 */
public class BigCharFactory {


    private HashMap<String, BigChar> pool = new HashMap<>();

    private static BigCharFactory singleton = new BigCharFactory();

    private BigCharFactory() {

    }

    public static BigCharFactory getInstance() {
        return singleton;
    }

    public synchronized BigChar getBigChar(char charName) {
        return pool.computeIfAbsent(String.valueOf(charName),
                charStr -> {
                    BigChar bigChar = new BigChar(charName);
                    pool.put(charStr, bigChar);
                    return bigChar;
                });
    }


}
